﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Net.Fan.SmallPig.DataAccess;
using System.Data;
using Net.Fan.SmallPig.BusinessRules;
using System.Drawing;

public partial class Job_Recently : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack == false)
        {
            bindDatas();

            RiskBiz.CheckRisks();
        }
    }

    private void bindDatas()
    {
        DataTable recentlyData = DynamicDA.GetRecentlyOperates();
        GridViewRecently.DataSource = recentlyData;
        GridViewRecently.DataBind();
        DataTable risks = RiskDA.GetRisks();
        GridViewRisk.DataSource = risks;
        GridViewRisk.DataBind();

    }

    protected void GridViewRisk_SelectedIndexChanged(object sender, EventArgs e)
    {

    }

    protected void GridViewRisk_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        TableCell tc = e.Row.Cells[4];
        if (tc.Text == "快到期")
        {
            tc.BackColor = Color.YellowGreen;
        }
    }

    protected void Timer1_Tick(object sender, EventArgs e)
    {
        LabelUpdateTime.Text = DateTime.Now.ToString("yy年MM月dd日 HH时mm分ss秒");
        bindDatas();
        RiskBiz.CheckRisks();

    }

    protected void GridViewRecently_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        string stime = e.Row.Cells[4].Text;
        DateTime dTime;
        DateTime.TryParse(stime, out dTime);
        TimeSpan ts = DateTime.Now - dTime;
        if (ts.TotalMinutes < 100)
        {
            e.Row.Cells[2].BackColor = Color.SeaGreen;
            e.Row.Cells[2].ForeColor = Color.White;
        }

    }
}
